package com.zl.service.impl;

import com.zl.dao.DeptDao;
import com.zl.pojo.Dept;
import com.zl.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao dd;
    @Autowired
    @Qualifier("redisTemplate")
    private RedisTemplate rt;
    @Override
    public List<Dept> queryAllDept() {
        ValueOperations vo = rt.opsForValue();
        List<Dept> depts = (List<Dept>) vo.get("depts");
        if(depts == null){
            depts=dd.queryAllDept();
        }
        vo.set("depts",depts);
        for(Dept d : depts){
            System.out.println("vo.set(\"depts\",depts);     " + d.toString());
        }
        return depts;
    }
}
